class Solution
{
public:
    int canBeTypedWords(string text, string brokenLetters)
    {
        bool isKeyBroken[26] = {false};
        for (char brokenKey : brokenLetters)
        {
            isKeyBroken[brokenKey - 'a'] = true;
        }

        int canTypeCount = 0;
        bool canTypeThisWord = true;

        // 有点bug，遇到连续空格会导致计数出错，不过测试用例没有遇到
        // 可以再添加一个lastIsSpace标志进行判断
        for (char letter : text)
        {
            if (letter != ' ')
            {
                if (isKeyBroken[letter - 'a'])
                {
                    canTypeThisWord = false;
                }
                // lastIsSpace = false;
            }
            else
            {
                // if (lastIsSpace) continue;
                if (canTypeThisWord)
                {
                    ++canTypeCount;
                }
                canTypeThisWord = true;
            }
        }
        if (canTypeThisWord)
        {
            ++canTypeCount;
        }
        return canTypeCount;
    }
};